local skuIds = KEYS
local counts = ARGV

local skuInventory = "inventory:"

local response = 1;

for i = 1, #skuIds do

    local exists = redis.call("EXISTS",skuInventory ..skuIds[i]);
    local inventory = redis.call("GET",skuInventory ..skuIds[i]);

    if exists == 0 then
        inventory = 0
    end

    if tonumber(counts[i]) > tonumber(inventory) then
        response = 0
    else
        redis.call("DECRBY",skuInventory ..skuIds[i],tonumber(counts[i]))
    end

end

return response